﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;

namespace CPPEI.ETL.TESTWEB
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetString()
        {
            return "Hello World";
        }

        [WebMethod]
        public string GetStringWithParams(string p1, string p2)
        {
            return string.Format("{0}_{1}", p1, p2);
        }

        [WebMethod]
        public int GetInt()
        {
            return new Random().Next(0, 100);
        }

        [WebMethod]
        public int GetIntWidthParams(int seed)
        {
            return new Random().Next(0, 100) + seed;
        }


        [WebMethod]
        public Data1 GetObject(Data1 d1,Data1 d2)
        {
            Data1 d = new Data1();
            d.Name = "1";
            d.Value = 122;
            return d;
        }

        [WebMethod]
        public DataTable GetDataTable(string v1, DateTime v2)
        {
            DataTable d1 = new DataTable("table1");
            for(int c = 0; c < 5; c++)
            {
                DataColumn column = new DataColumn(string.Format("c{0}", c));
                if (c == 3)
                {
                    column.DataType = typeof(DateTime);
                }
                else if(c == 4)
                {
                    column.DataType = typeof(Guid);
                }
                d1.Columns.Add(column);
            }

            for (int row = 0; row < 4; row++)
            {
                DataRow dRow = d1.NewRow();
                dRow["c0"] = string.Format("r{0}", row);
                dRow["c1"] = string.Format("r{0}", row);
                dRow["c2"] = string.Format("r{0}", row);
                dRow["c3"] = DateTime.Now.AddDays(row);
                dRow["c4"] = Guid.NewGuid();

                d1.Rows.Add(dRow);
            }
            return d1;
        }

        [WebMethod]
        public XmlNode GetXmlNode(string v3, int v4, Guid v5)
        {
            string xmlString = "<data><item><p1>1</p1><p2>abc1</p2></item><item><p1>2</p1><p2>abc2</p2></item></data>";
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(xmlString);
            return xDoc.SelectSingleNode("./data");
        }

        [WebMethod]
        public XmlDocument GetXmlDoc(string v3, int v4, Guid v5)
        {
            string xmlString = "<data><item><p1>1</p1><p2>abc1</p2></item><item><p1>2</p1><p2>abc2</p2></item></data>";
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(xmlString);
            return xDoc;
        }
    }

    public class Data1
    {
        public string Name { get; set; }
        public double Value { get; set; }
    }
}
